﻿using LimaLims.Application.Service.Base.Dto;
using LimaLims.Application.Service.Basic.Dto;
using LimaLims.Core;
using LimaLims.Core.Entity.TestCenter;
using LimaLims.Core.Enum;
using LimaLims.Core.Util;
using Microsoft.EntityFrameworkCore;

namespace LimaLims.Application.Service.TestCenter.Dto
{
    /// <summary>
    /// 任务明细
    /// </summary>
    public class ExperimentTaskDetail
    {
        public ExperimentTaskOutput ExperimentTask { get; set; }
        /// <summary>
        /// 试验内容与规则
        /// </summary>
        public ICollection<InspectionDataOutput> InspectionTableData { get; set; }

    }

    /// <summary>
    /// 任务进度详细
    /// </summary>
    public class ExperimentTaskStepDetail
    {
        /// <summary>
        /// 任务步骤
        /// </summary>
        public string SetpName { get; set; }

        /// <summary>
        /// 是否完成
        /// </summary>
        public bool IsCompleted { get; set; }

        /// <summary>
        /// 是否合格
        /// </summary>
        public bool IsPass { get; set; }

        /// <summary>
        /// 试验项目类别
        /// </summary>
        public InspectionType InspectionType { get; set; }

        /// <summary>
        /// 试验项目类别
        /// </summary>
        public string InspectionTypeValue => InspectionType.ToString();
    }

    /// <summary>
    /// 试验任务DTO
    /// </summary>
    public class ExperimentTaskOutput
    {
        public long Id { get; set; }

        public string TaskCode { get; set; }

        public long ExperimentPlanId { get; set; }

        public string ExperimentPlanCode { get; set; }

        public string TeamName { get; set; }

        /// <summary>
        /// 试验方案
        /// </summary>
        public string InspectionSchemeName { get; set; }
        /// <summary>
        /// 试验员Id
        /// </summary>
        public long? ExperimentUserId { get; set; }

        /// <summary>
        /// 试验员名称
        /// </summary>
        public string ExperimentUserName { get; set; }
        
        public ExperimentType Type { get; set; }

        public string TypeText =>this.Type.GetDescription();

        /// <summary>
        /// 计划开始时间
        /// </summary>
        public DateTime PlanStartTime { get; set; }

        /// <summary>
        /// 计划完成时间
        /// </summary>
        public DateTime PlanEndTime { get; set; }

        /// <summary>
        /// 实际开始时间
        /// </summary>
        public DateTime? ActualStartTime { get; set; }

        /// <summary>
        /// 实际完成时间
        /// </summary>
        public DateTime? ActualEndTime { get; set; }

        /// <summary>
        /// 试验对象ID
        /// </summary>
        public long TargetId { get; set; }

        /// <summary>
        /// 试验对象编号
        /// </summary>
        public string TargetCode { get; set; }

        /// <summary>
        /// 试验对象名称
        /// </summary>
        public string TargetName { get; set; }

        /// <summary>
        /// 出厂编号
        /// </summary>
        public string FactoryNumbe { get; set; }

        /// <summary>
        /// 不良品处理结果
        /// </summary>
        public long RejectsHandlingId { get; set; }

        /// <summary>
        /// 不合格原因描述
        /// </summary>
        public string RejectsRemark { get; set; }

        /// <summary>
        /// 任务状态
        /// </summary>
        public ExperimentStatus Status { get; set; }

        public string StatusText => this.Status.GetDescription();

        /// <summary>
        /// 试验结果
        /// </summary>
        public ExperimentResult? Result { get; set; }

        public string ResultText => this.Result.HasValue ? this.Result.GetDescription() : "";

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreatedTime { get; set; }

        /// <summary>
        /// 试验报告URL
        /// </summary>
        public string ReportUrl { get; set; }
    }

    /// <summary>
    /// 完工处理INPUT
    /// </summary>
    public class CompletedInput
    {
        /// <summary>
        /// 试验结果
        /// </summary>
        public ExperimentResult TaskResult { get; set; }

        /// <summary>
        /// 试验任务Id
        /// </summary>
        public long ExperimentTaskId { get; set; }

        /// <summary>
        /// 不良原因
        /// </summary>
        public ICollection<RejectItemInput> RejectItems { get; set; }
    }

    /// <summary>
    /// 试验任务分页
    /// </summary>
    public class ExperimentTaskPageInput : PageInputBase
    {
        /// <summary>
        /// 任务编号
        /// </summary>
        public string TaskCode { get; set; }

        /// <summary>
        /// 试验人员ID
        /// </summary>
        public long? ExperimentUserId { get; set; }

        /// <summary>
        /// 试验人员
        /// </summary>
        public string ExperimentUserName { get; set; }

        /// <summary>
        /// 计划编号
        /// </summary>
        public string ExperimentPlanCode { get; set; }

        /// <summary>
        /// 班组
        /// </summary>
        public long? TeamId { get; set; }

        /// <summary>
        /// 方案
        /// </summary>
        public long? InspectionSchemeId { get; set; }

        /// <summary>
        /// 任务状态
        /// </summary>
        public ExperimentStatus? Status { get; set; }=ExperimentStatus.NotStarted;

        /// <summary>
        /// 任务结果
        /// </summary>
        public ExperimentResult? Result { get; set; }
    }
}
